var gadgets = gadgets || {};
gadgets.window = gadgets.window || {};

var oldHeight;

//this is mostly stollen from apache shinding dynamic-height.js
gadgets.window.getViewportDimensions = function() {
    var x,y;
    if (self.innerHeight) {
        x = self.innerWidth;
    y = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
    } else if (document.body) {
        x = document.body.clientWidth;
        y = document.body.clientHeight;
    } else {
        x = 0;
        y = 0;
    }
    return {width: x, height: y};
}

//this is mostly stollen from apache shinding dynamic-height.js
function _IG_AdjustIFrameHeight(opt_height) {
    var newH = parseInt(opt_height, 10);
    if (isNaN(newH)) {
        var vh = gadgets.window.getViewportDimensions().height;
        var bod = document.body;
        var docEl = document.documentElement;
        if (document.compatMode == 'CSS1Compat' && docEl.scrollHeight) {
            newH = docEl.scrollHeight != vh ? docEl.scrollHeight : docEl.offsetHeight;
        } else {
            var sh = docEl.scrollHeight;
            var oh = docEl.offsetHeight;
            if (docEl.clientHeight != oh) {
                sh = body.scrollHeight;
                oh = body.offsetHeight;
            }
            if (sh > vh) {
                newH = sh > oh ? sh : oh;
            } else {
        newH = sh < oh ? sh : oh;
            }
        }
    }
    if (newH != oldHeight) {
        newH += 20;
        top.resizeFrame(module_id, newH);
    }
};
gadgets.window.adjustHeight = _IG_AdjustIFrameHeight;